package com.ncloud.resman.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.ncloud.resman.mapper.CabinetMapper;
import com.ncloud.resman.mapper.DeviceBaseMapper;
import com.ncloud.resman.mapper.DeviceIpMapper;
import com.ncloud.resman.mapper.DeviceMapMapper;
import com.ncloud.resman.mapper.DeviceServerMapper;
import com.ncloud.resman.mapper.DeviceUnitMapper;
import com.ncloud.resman.mapper.SequenceMapper;
import com.ncloud.resman.mapper.SwitchMapper;
import com.ncloud.resman.mapper.SwitchSubMapper;
import com.ncloud.resman.service.DeviceMapService;
@Service
public class DeviceMapServiceImpl implements DeviceMapService{
	@Resource
	private DeviceMapMapper deviceMapMapper;
	@Resource
	private CabinetMapper cabinetMapper;
	@Resource
	private DeviceBaseMapper deviceBaseMapper;
	@Resource
	private DeviceServerMapper deviceServerMapper;
	@Resource
	private DeviceUnitMapper deviceUnitMapper;
	@Resource
	private DeviceIpMapper deviceIpMapper;
	@Resource
	private SwitchMapper switchMapper;
	@Resource
	private SwitchSubMapper switchSubMapper;
	@Resource
	private SequenceMapper sequenceMapper;

	@Override
	public JSONObject getDeviceMapBase(JSONObject json) {
		Integer roomId=json.getInteger("roomId");
		Long cabinetId=json.getLong("cabinetId");
		JSONObject result =new JSONObject();
		List<JSONObject> rooms=deviceMapMapper.getRoomInfoById(roomId);
		if(rooms!=null&&rooms.size()>0){
			result.put("room", rooms.get(0));
		}
		List<JSONObject> cabinets=cabinetMapper.getCabinetInfoById(roomId, cabinetId);
		if(cabinets!=null&&cabinets.size()>0){
			result.put("cabinet", cabinets.get(0));
		}
		List<JSONObject> cabinetUses=deviceMapMapper.getCabinetUseById(cabinetId);
		if(cabinetUses!=null&&cabinetUses.size()>0){
			result.put("cabinetUse", cabinetUses);
		}
		return result;
	}

	@Override
	public JSONObject getDeviceMapServer(JSONObject json) {
		Long deviceId=json.getLong("deviceId");
		JSONObject result =new JSONObject();
		List<JSONObject> deviceBases=deviceBaseMapper.getDeviceBaseById(deviceId);
		if(deviceBases!=null&&deviceBases.size()>0){
			result.put("deviceBase", deviceBases.get(0));
		}
		List<JSONObject> deviceServers=deviceServerMapper.getDeviceServerById(deviceId);
		if(deviceServers!=null&&deviceServers.size()>0){
			result.put("deviceServer", deviceServers.get(0));
		}
		List<JSONObject> deviceUnits=deviceUnitMapper.getDeviceUnitById(deviceId);
		if(deviceUnits!=null&&deviceUnits.size()>0){
			result.put("deviceUnit", deviceUnits);
		}
		List<JSONObject> deviceIps=deviceIpMapper.getDeviceIpById(deviceId);
		if(deviceIps!=null&&deviceIps.size()>0){
			result.put("deviceIp", deviceIps);
		}
		return result;
	}

	@Override
	public JSONObject getDeviceMapSwitch(JSONObject json) {
		Long deviceId=json.getLong("deviceId");
		JSONObject result =new JSONObject();
		List<JSONObject> deviceBases=deviceBaseMapper.getDeviceBaseById(deviceId);
		if(deviceBases!=null&&deviceBases.size()>0){
			result.put("deviceBase", deviceBases.get(0));
		}
		List<JSONObject> deviceSwitchs=switchMapper.getDeviceSwitchById(deviceId);
		if(deviceSwitchs!=null&&deviceSwitchs.size()>0){
			result.put("deviceSwitch", deviceSwitchs.get(0));
		}
		List<JSONObject> deviceSwitchSubs=switchSubMapper.getDeviceSwitchSubById(deviceId);
		if(deviceSwitchSubs!=null&&deviceSwitchSubs.size()>0){
			result.put("deviceSwitchSub", deviceSwitchSubs);
		}
		return result;
	}

	@Override
	public JSONObject getDeviceMapFirewall(JSONObject json) {
		Long deviceId=json.getLong("deviceId");
		JSONObject result =new JSONObject();
		List<JSONObject> deviceBases=deviceBaseMapper.getDeviceBaseById(deviceId);
		if(deviceBases!=null&&deviceBases.size()>0){
			result.put("deviceBase", deviceBases.get(0));
		}
		return result;
	}
}
